/**
* @depends jquery.ui.js
*/

(function($) {

	$.widget( 'ui.widget_searchbar_result', {
		
		_init: function() {
		
			var $this = this;
			
			this.element
				.click( function() {
					location.href = $(this).attr( 'href' );
				} )
				.mouseover( function() {
					$this.select();
				} );
			
		
		},
		
		select: function() {
			if( this.element.hasClass( 'Selected' ) ) {
				return this;
			}
			this.element.closest( 'ul' ).find( '.Selected' ).removeClass( 'Selected' );
			this.element.addClass( 'Selected' );
			return this;
		},
		
		select_next: function() {
			var li = this.element.parent();
			if( li.next().length ) {
				li.next().find( '.SearchResult' ).widget_searchbar_result( 'select' );
			}
			else {
				this.element.removeClass( 'Selected' );
			}
		},

		select_previous: function() {
			var li = this.element.parent();
			if( li.prev().length ) {
				li.prev().find( '.SearchResult' ).widget_searchbar_result( 'select' );
			}
			else {
				this.element.removeClass( 'Selected' );
			}
		}
		
	} );
	
})(jQuery);

